package 多线程;

/**
 * @Author: 李佳芬
 * @Description: 多个线程操作同一个对象
 * @DateTime: 2023/3/27 15:57
 **/
public class TestThread4 implements Runnable{

    // 定义十张车票
    private int chepiao = 10;

    public static void main(String[] args) {

        TestThread4 testThread4 = new TestThread4();
        new Thread(testThread4,"佳芬").start();
        new Thread(testThread4,"黄牛").start();
        new Thread(testThread4,"小明").start();
        new Thread(testThread4,"陆泽远").start();

    }

    @Override
    public void run() {
        while (true){
            if (chepiao<=1){
                break;
            }
            // 模拟抢票延迟
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第"+chepiao+"票"+chepiao--);
        }

    }
}
